
import { createRouter } from 'uni-mini-router'

const router = createRouter({ routes: [...ROUTES] })
console.log(ROUTES);
router.beforeEach((to, from, next) => {

  const token = uni.getStorageSync('token')
  if (to.meta?.requiresAuth && !token) {
	  
	  	console.log(to);
    return next({ path: '/pages/index/login',query:{...to?.query??{},...{'chech':""}}})
  }
  next()
})
export function setupRouter(app) {
  app.use(router)
}

export { router }


// import  createRouter  from 'uni-simple-router'
// import type { App } from 'vue'

// // 自动生成路由表（无需手动维护）
// const ROUTES = window.ROUTES || []

// const router = createRouter({
//   platform: process.env.VUE_APP_PLATFORM,
//   routes: ROUTES.map(page => ({
//     path: page.path,
//     name: page.name,
//     component: () => import(`@/pages/${page.path}/index.vue`),
//     meta: {
//       title: page.title || '默认标题',
//       requiresAuth: page.meta?.auth || false
//     }
//   }))
// })

// // 全局路由守卫
// router.beforeEach((to, from, next) => {
//   if (to.meta.requiresAuth && !isLogin()) {
//     next('/pages/login')
//   } else {
//     next()
//   }
// })

// export function setupRouter(app: App) {
//   app.use(router)
// }




